home *** CD-ROM | disk | FTP | other *** search
- /*
- * Version numbering for EPSILON.
- *
- * Copyright (c) 1986 by David Dyer-Bennet
- * Permission for non-commercial use is hereby granted; all other
- * rights are reserved.
- *
- * Written by David Dyer-Bennet
- * Terrabit Software
- * 4242 Minnehaha Ave S
- * Minneapolis, MN 55406
- * Sysop of Fido 14/341, The Terraboard, (612) 721-8967 3/12/24 24hrs
- * (612) 721-8800 NOT 24 hrs! More like noon to midnight
- */
-
- /*
- * For certain file types (identified by setting buffer int vers_edit
- * in their mode routines) this provides support for multiple versions
- * of the file to exist at once. The file foo.mss will contain
- * the latest version of the file; old versions of the
- * file will be in foo.m01, foo.m02, etc. foo.mzz will contain information
- * about the file ("m" is specified in
- * the master file).
- *
- * The format of this master file is the same as an environment table.
- */
-
- /*
- * Revision history:
- *
- * Edit Date Who Description
- *
- * Version T1.0 (Alpha test)
- * 1 5-Apr-86 DD-B Initial creation
- * 2 6-Apr-86 DD-B Keep latest version in normal name
- */
-
- #include <eel.h>
- #include "versions.h"
-
- int getpsenv (name)
- char *name;
- /*
- * Get the value of an environment variable stored in the current buffer.
- * (Returns pointer to start);
- */
- {
- point = 0;
- if ((!search (1, name)) || (!search (1, "="))) {
- return NULL;
- }
- while (isspace (curchar ())) point++; /* Skip over space */
- return point;
- }
-
- int atoi (s)
- char *s;
- {
- int i = 0;
-
- while (isspace (*s)) s++;
- while (isdigit (*s))
- i = i * 10 + *s++ - '0';
- return i;
- }
-
- versions_edit (extchar)
- char extchar;
- {
- int i, vers;
- char verstr [10], *oldbuf, mbuf [FNAMELEN], vmast [FNAMELEN];
-
- /*
- * Find proper data file based on EXTCHAR and CURVER parameters in
- * master file.
- */
-
- /* Remember extension character */
- vers_extchar = extchar;
- strcpy (vers_name, filename);
-
- /* Make up master file name */
- strcpy (vmast, filename);
- i = get_extension (vmast) - vmast;
- i += 1; /* Leave the dot */
- vmast [i++] = extchar;
- strcpy (&vmast [i], "ZZ");
-
- /* Grab master file into a buffer */
- strcpy (mbuf, bufname);
- strcat (mbuf, "<V>");
- zap (mbuf);
- oldbuf = bufname;
- bufname = mbuf;
- filename = vmast;
- if (file_read (vmast, 1)) {
- stuff ("CURVER = 0\n");
- vers = -1;
- } else {
- if (!getpsenv ("CURVER")) {
- error ("\"CURVER\" not found in %s", filename);
- }
- i = point;
- nl_forward (); point--;
- grab (i, point, verstr);
- vers = atoi (verstr);
- if (vers == 99) {
- error ("File version wraparound, time to purge");
- }
- }
-
- bufname = oldbuf;
- vers_version = vers + 1;
- }
-
- int versions_save ()
- /*
- * Called by save_file before the file connected to the buffer is
- * actually saved, if the file is a versioned file and if the file
- * name matches the versioned name. The purpose of this routine
- * is to update the master file.
- *
- * On entry the buffer being saved will be current.
- */
- {
- int i, vers;
- char *oldbuf, mbuf [FNAMELEN], oldfn [FNAMELEN], verstr [3], *p;
-
- /* Make up name for next version of old file */
- if (vers_version >= 0) {
- strcpy (oldfn, filename);
- p = get_extension (oldfn);
- p += 1; /* Skip over dot */
- *p++ = vers_extchar;
- sprintf (p, "%02.2d", vers_version - 1);
- rename_file (filename, oldfn); /* Rename old version */
- }
- vers = vers_version;
-
- /* Update the master file */
- oldbuf = bufname;
- strcpy (mbuf, bufname);
- strcat (mbuf, "<V>");
- bufname = mbuf;
-
- if (!getpsenv ("CURVER")) {
- error ("\"CURVER\" not found in %s", filename);
- }
-
- i = point;
- nl_forward ();
- point--;
- delete (i, point);
- bprintf ("%d", vers);
- file_write (filename, 1);
- bufname = oldbuf;
-
- vers_version += 1;
- }
-
- command version_statistics ()
- {
- char relname [FNAMELEN];
-
- if (vers_edit) {
- relative (vers_name, relname);
- say ("Version %d, Master %s, Ext %c", vers_version, relname,
- vers_extchar);
- } else {
- say ("Not versioned");
- }
- }
-
- command un_version ()
- {
- vers_edit = 0;
- say ("Versioning disabled");
- }
-
- /* End of versions.e */
-